package sector.soda.input;

import com.jme3.app.Application;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import sector.soda.states.GameState;
import sector.soda.states.MenuState;

public class MainMenuController implements ScreenController {
    
    private Application app;

    public MainMenuController(Application app) {
        this.app = app;
    }

    public void bind(Nifty nifty, Screen screen) {
    }

    public void onStartScreen() {
    }

    public void onEndScreen() {
    }

    public void startGame() {  
        /* Get current menu state. When in menu detach
         * and load GameState */
        MenuState menuState = app.getStateManager().getState(MenuState.class);
        
        if (menuState != null && menuState.isActive()) {
            app.getStateManager().detach(menuState);
            
            GameState state = app.getStateManager().getState(GameState.class);
        
            if (state != null && !state.isActive()) {
                state.setActive(true);
            } else {
                GameState gameState = new GameState();
                app.getStateManager().attach(gameState);
            }
        }
    }
}